package jwdt.xadmin.added.action;

import jwdt.common.action.BaseAction;
import jwdt.xadmin.added.bean.TImages;
import jwdt.xadmin.added.service.ImageManageService;
import jwdt.xadmin.system.service.FlmxManageService;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;
import com.ezerg.web.fileupload.FileItem;

@Controller("/xadmin/added")
public class ImageManageAction extends BaseAction {

	private FlmxManageService flmxManageService = (FlmxManageService)app.getBean("flmxManageService");
	private ImageManageService imageManageService = (ImageManageService)app.getBean("imageManageService");
	
	@RequestMapping("/listImages")
	public Page doListImage(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		return m.getWritePage(f, imageManageService.doList(pu).toJson());
	}
	
	@RequestMapping("/addImages")
	public Page doAddact(Form f, Module m) throws Exception {
		TImages obj = (TImages)f.copy2Class(TImages.class);
		FileItem file = f.getFileItem("imgfile");
		return m.getWritePage(f, imageManageService.doAddact(obj,file));
	}
	
	@RequestMapping("/editImages")
	public Page doEditact(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		TImages obj = (TImages)f.copy2Class(TImages.class);
		FileItem file = f.getFileItem("imgfile");
		return m.getWritePage(f, imageManageService.doEditact(obj,id,file));
	}
	
	@RequestMapping("/delImages")
	public Page doDel(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		return m.getWritePage(f, imageManageService.doDelact(id));
	}
	
	@RequestMapping("/shenheImages")
	public Page doShenhe(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		String result = f.getString("result");
		return m.getWritePage(f, imageManageService.doUpdateState(id, result));
	}
	
	@RequestMapping("/listPositionForCombox")
	public Page doListFlmxForCombox(Form f, Module m) throws Exception {
		int flid = 6;
		//生成json字符串
    	return m.getJsonPage(f, flmxManageService.doListForCombo(flid));
	}
	
	@RequestMapping("/imagesWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		f.add("obj", imageManageService.doLoad(id));
		return m.defaultPage();
	}
}
